<?php


function is_cached ($filename, $time) 
{
	$file = 'modules/system/cache/'.$filename;
	if (file_exists ($_SERVER['DOCUMENT_ROOT'].'/'.$file)) 
	{
		if (filemtime ($_SERVER['DOCUMENT_ROOT'].'/'.$file) > (time() - $time)) 
			return true;
		else 
			return false;
	}
	else 
		return false;
}

function clear_cached($filename)
{
	$file = 'modules/system/cache/'.$filename;
	if (file_exists ($file)) 
		unlink ($file);
}

function get_cached($filename)
{
	$file = 'modules/system/cache/'.$filename;
	if (file_exists ($file)) 
		return file_get_contents ($file);
}

function cache_file ($filename, $content) 
{
	$file = 'modules/system/cache/'.$filename;
	clear_cached($filename);
	
	$cache_file = fopen ($_SERVER['DOCUMENT_ROOT'].'/'.$file, 'w');
	flock ($cache_file, LOCK_EX);
	fwrite ($cache_file, $content);
	flock ($cache_file, LOCK_UN);
	fclose ($cache_file);
}


?>
